package com.itcast.admin.controller;

import com.itcast.common.model.dto.request.SetmealCategoryAddRepDTO;
import com.itcast.common.model.dto.request.SetmealCategoryReqDTO;
import com.itcast.common.model.dto.response.SetmealCategoryResDTO;
import com.itcast.security.service.ISetmealCategoryService;
import com.jzo2o.common.model.PageResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* <p>
* setmeal_category 控制器实现
* </p>
*
* @author Administrator
* @since 2024-11-05 16:08:22
*/
@RestController
@RequestMapping("admin/setmeal-category")
public class SetmealCategoryController {

    @Autowired
    private ISetmealCategoryService setmealCategoryService;

    @GetMapping("/pageQuery")
    @ApiOperation("套餐类型分页查询")
    public PageResult<SetmealCategoryResDTO> page(SetmealCategoryReqDTO setmealCategoryReqDTO) {
        PageResult<SetmealCategoryResDTO> list = setmealCategoryService.querySetmealCategoryList(setmealCategoryReqDTO);
        return list;
    }


    /**
     * 新增套餐类型
     */
    @PostMapping
    public void add(@RequestBody SetmealCategoryAddRepDTO setmealCategoryAddRepDTO) {
        setmealCategoryService.saveSetmealCategory(setmealCategoryAddRepDTO);
    }

    /**
     * 根据id查询套餐类型
     */
    @GetMapping("/{id}")
    public SetmealCategoryResDTO getById(@PathVariable Long id) {
        SetmealCategoryResDTO setmealCategoryResDTO = setmealCategoryService.getByIdSetmeal(id);
        return setmealCategoryResDTO;
    }


    /**
     * 修改套餐类型
     */
    @PutMapping("/{id}")
    public void update(@PathVariable Long id, @RequestBody SetmealCategoryAddRepDTO setmealCategoryAddRepDTO) {
        setmealCategoryService.updateByIdSMC(id, setmealCategoryAddRepDTO);
    }

    /**
     * 启用套餐类型
     */
    @PutMapping("/enable/{id}")
    public void enable(@PathVariable Long id) {
        setmealCategoryService.enable(id);
    }

    /**
     * 删除套餐类型
     */
    @DeleteMapping("/{id}")
    public void remove(@PathVariable Long id){
        setmealCategoryService.removeSetmealCategory(id);
    }

    /**
     * 查询套餐类型下拉列表
     */
    @GetMapping("/listForFilter")
    public List<SetmealCategoryResDTO> selectList(){
        return setmealCategoryService.listSetmeal();
    }

}
